package com.gexiaobao.pigeon.ui.adapter

import android.annotation.SuppressLint
import androidx.recyclerview.widget.GridLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.ViewCommentsResponse
import com.gexiaobao.pigeon.databinding.ItemViewCommentsBinding
import com.gexiaobao.pigeon.ui.view.StarRatingBar

/**
 * @Author      : hxw
 * @Date        : 2023/6/28 14:58
 * @Describe    :
 */
class ProductEvaluateAdapter(data: ArrayList<ViewCommentsResponse.ListBean>) :
    BaseQuickAdapter<ViewCommentsResponse.ListBean, DataBindBaseViewHolder>(R.layout.item_view_comments, data) {

    @SuppressLint("NotifyDataSetChanged")
    override fun convert(holder: DataBindBaseViewHolder, item: ViewCommentsResponse.ListBean) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemViewCommentsBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        val starViewComments = holder.getView<StarRatingBar>(R.id.starViewComments)
        starViewComments.setStar(item.goodsRating.toFloat())

        holder.itemView.apply {
            binding.rvViewComments.adapter = null
            if (item.images == null || item.images.isEmpty()) {
                holder.setGone(R.id.rvViewComments, true)//隐藏
                return
            }
            holder.setGone(R.id.rvViewComments, false)//显示
            val mAdapterGoods = EvaluateImageAdapter(item.imgPath)
            binding.rvViewComments.apply {
                layoutManager = GridLayoutManager(context, 3)
                adapter = mAdapterGoods
                mAdapterGoods.notifyDataSetChanged()
            }
        }
    }
}